package com.snbc.Exception;

import java.io.*;

public class TestException1 {
    String TAG = "TestException1";

    public static void main(String[] args) {

        // System.out.println(readFile());
        System.out.println("===========================================");
        System.out.println(readfile1());
    }

    private static String readfile1() {
        BufferedReader bufferedReader = null;
        StringBuffer sb = new StringBuffer();
        File file = new File("F:\\sougou\\SogouInput\\readme.txt");
        try {
            FileReader fr = new FileReader(file);
            bufferedReader = new BufferedReader(fr);
            String nextline = "";
            while ((nextline = bufferedReader.readLine()) != null) {
                sb.append(nextline);
            }
            return sb.toString();
        } catch (FileNotFoundException e) {
            System.out.println(file.getName() + " 文件不存在");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("bufferedReader:关闭异常");

            }
        }
        return sb.toString();
    }

    private static String readFile() {
        File file = new File("F:\\sougou\\SogouInput\\readme.txt");
        BufferedReader reader = null;
        StringBuffer sbf = new StringBuffer();
        try {
            FileReader fr = new FileReader(file);
            reader = new BufferedReader(fr);
            //reader = new BufferedReader(new FileReader(file));
            String nextline = "";
            while ((nextline = reader.readLine()) != null) {
                sbf.append(nextline);
            }
            reader.close();
            return sbf.toString();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return sbf.toString();
    }
}